﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BSCMFF.Core.MembershipDataProvider;

namespace BSCMFF.Core.DataAccessLayer
{
    /// <summary>
    /// Expands generated class User
    /// </summary>
    /// <remarks></remarks>
    public partial class User
    {
        private string fullname;
        /// <summary>
        /// Gets the fullname.
        /// </summary>
        /// <remarks></remarks>
        public string Fullname
        {
            get
            {
                {
                    if (fullname == null)
                    {
                        fullname = this.Firstname + " " + this.Lastname;
                    }
                    return fullname;
                }
            }
        }

        /// <summary>
        /// Gets the current evaluation ID.
        /// </summary>
        /// <remarks></remarks>
        public int CurrentEvaluationID
        {
            get
            {
                if (this.Evaluation_Evaluator_Employee.Count != 0)
                {
                    return this.Evaluation_Evaluator_Employee.First().ID;
                }
                else
                {
                    return 0;
                }
            }
        }

        /// <summary>
        /// Gets the current EEE.
        /// </summary>
        /// <remarks></remarks>
        public Evaluation_Evaluator_Employee CurrentEEE
        {
            get
            {
                if (this.Evaluation_Evaluator_Employee.Count != 0)
                {
                    return this.Evaluation_Evaluator_Employee.First();
                }
                else
                {
                    return null;
                }
            }
        }

        /// <summary>
        /// Gets the total Personal KPIs weight.
        /// </summary>
        /// <remarks></remarks>
        public int TotalPKPIsWeight
        {
            get
            {
                BSCEntities context = new BSCEntities();

                List<int> total = (from pkpis in context.Personal_KPI
                                   where pkpis.User_FK == this.ID
                                   select pkpis.Weight).ToList();

                if (total == null)
                {
                    return 0;
                }
                else
                {
                    return total.Sum();
                }
            }
        }
    }
}
